<template>
  <div>
    <el-form @submit.prevent="login">
      <el-form-item label="用户名">
        <el-input v-model="username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: ''
    };
  },
  methods: {
    async login() {
      try {
        const response = await this.axios.post(this.$https+'/api/Report/login', {
          username: this.username,
          password: this.password
        });
        this.$message.success(response.data);
        localStorage.setItem('user', JSON.stringify({ username: this.username }));
        this.$router.push('/list');
      } catch (error) {
        this.$message.error('登录失败');
      }
    }
  }
};
</script>